package com.khh.dao;

import com.khh.entity.Book;
import com.khh.entity.Student;
import lombok.Data;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by webrx on 2017-09-15.
 */
@Data
@Repository
public class StudentDao {

    @Resource(name="sf")
    protected SessionFactory sf;

    //查询
    public List<Student> query(){
        Session session  = sf.openSession();
        return session.createQuery("from Student").list();
    }

    //插入
    public void insert(Student stu){
        Session session  = sf.openSession();
        session.beginTransaction();
        session.save(stu);
        session.getTransaction().commit();
        session.close();
    }
}
